//
//  PersonalInformationViewController.m
//  FreeTravel
//
//  Created by 徐康 on 16/8/27.
//  Copyright © 2016年 KX. All rights reserved.
//
#import "FreeTravelMacro.h"
#import "PersonalInformationViewController.h"
#import "Masonry.h"
#import "FreeTravelNetwork.h"
@interface PersonalInformationViewController ()

@end

@implementation PersonalInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    self.navigationItem.title = @"手机号注册";
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    self.view.backgroundColor = [UIColor colorWithRed:0.11 green:0.68 blue:0.45 alpha:1.00];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"sdfasadfas"] style:UIBarButtonItemStylePlain target:self action:@selector(goLogin)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.userTextField = [[UITextField alloc]init];
    [self.view addSubview:self.userTextField];
    self.userTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"填写您的用户名" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.userTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view).multipliedBy(0.3);
        make.width.equalTo(self.view).multipliedBy(0.9);
        make.height.equalTo(self.view).multipliedBy(0.07);
    }];
    
    UIView *firstWhiteLine = [[UIView alloc]init];
    [self.view addSubview:firstWhiteLine];
    firstWhiteLine.backgroundColor = [UIColor whiteColor];
    [firstWhiteLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.centerX.equalTo(self.userTextField);
        make.height.mas_equalTo(2);
        make.top.equalTo(self.userTextField.mas_bottom);
        
    }];
    
    
    self.InvitationCodeTextField = [[UITextField alloc]init];
    [self.view addSubview:self.InvitationCodeTextField];
    self.InvitationCodeTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"邀请码(选填)" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.InvitationCodeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.userTextField);
        make.centerY.equalTo(self.view).multipliedBy(0.45);
        make.width.equalTo(self.view).multipliedBy(0.4);
        make.centerX.equalTo(self.view).multipliedBy(1.5);
    }];
    
    UIView *secondWhiteLine = [[UIView alloc]init];
    [self.view addSubview:secondWhiteLine];
    secondWhiteLine.backgroundColor = [UIColor whiteColor];
    [secondWhiteLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.centerX.equalTo(self.self.InvitationCodeTextField);
        make.height.mas_equalTo(2);
        make.top.equalTo(self.InvitationCodeTextField.mas_bottom);
        
    }];
    
    self.passwordTextField = [[UITextField alloc]init];
    [self.view addSubview:self.passwordTextField];
    self.passwordTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"填写密码(不少于8位)" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.centerY.equalTo(self.InvitationCodeTextField);
        make.left.equalTo(self.view.mas_left).mas_offset(self.view.frame.size.width/20);
        make.right.equalTo(self.InvitationCodeTextField.mas_left).mas_offset(-self.view.frame.size.width/20);
    }];
    
    UIView *thirdWhiteLine = [[UIView alloc]init];
    [self.view addSubview:thirdWhiteLine];
    thirdWhiteLine.backgroundColor = [UIColor whiteColor];
    [thirdWhiteLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.centerX.equalTo(self.self.passwordTextField);
        make.height.mas_equalTo(2);
        make.top.equalTo(self.passwordTextField.mas_bottom);
        
    }];
    
    
    UIButton *completeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:completeButton];
    [completeButton setTitle:@"完成" forState:UIControlStateNormal];
    [completeButton setTitleColor:COLORFORFREETRAVEL forState:UIControlStateNormal];
    completeButton.backgroundColor = [UIColor whiteColor];
    completeButton.layer.cornerRadius = 5;
    completeButton.layer.masksToBounds = YES;
    [completeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.equalTo(self.view);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(44);
    }];
    [completeButton addTarget:self action:@selector(complete:) forControlEvents:UIControlEventTouchUpInside];
    
    
}
- (void)complete:(UIButton *)button{
    NSLog(@"%@   %@   %@   %@",self.verification,self.phoneNum,self.passwordTextField.text,self.userTextField.text);
    NSString *str1 = @"account_s=d2a21bf8d23ac0b65bbe4211f703e772&account_type=2&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&code=";
    NSString *str2 = @"&count=20&grant_type=password&mobile=86-";
    NSString *str3 = @"&page=1&password=";
    NSString *str4 = @"&track_app_channel=App%2520Store&track_app_version=7.0.1&track_device_info=iPhone%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%25209.3.4&username=";
    NSString *str5 = @"&v=1";
    str1 = [[[[[[[[str1 stringByAppendingString:self.verification] stringByAppendingString:str2] stringByAppendingString:self.phoneNum] stringByAppendingString:str3] stringByAppendingString:self.passwordTextField.text ] stringByAppendingString:str4] stringByAppendingString:self.userTextField.text] stringByAppendingString:str5];
    
        [FreeTravelNetwork POST:@"http://open.qyer.com/qyer/user/signup" andBody:str1 andBodyStyle:ZWYBodyString andHeader:@{@"Host": @"open.qyer.com",@"Content-Type":@"application/x-www-form-urlencoded",@"Connection":@"keep-alive",@"Proxy-Connection":@" keep-alive",@"Cookie":@"__utma=253397513.2045201602.1472089545.1472193699.1472211994.9; __utmz=253397513.1472089545.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _guid=84639271-4ee1-e7cc-4fa4-85f96ce0f519; plan_token=49a54885675d4aa2755c0f6f6f596a9e; yqf_cps=source%3Demar%26channel%3Dcps%26cid%3D18526%26wi%3DNTEzNzAzfDAwMTBiNDU1NDU5OTYxODY0OTAz",@"User-Agent":@"QYER/7.0.1 (iPhone; iOS 9.3.4; Scale/2.00) Paros/3.2.13",@"Accept-Language":@"zh-Hans-CN;q=1, nl-CN;q=0.9, en-CN;q=0.8",@"Content-Length":@"382"} andResponse:ZWYJSON andSuccessBlock:^(id result) {
            NSLog(@"%@",result);
        } andFailureBlock:^(NSError *error) {
    
        }];
    
}
- (void)goLogin{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
